/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.array;

/**
 *
 * @author VANDH
 */
public class SortArray {

    public static void main(String[] args) {
        int[] array = new int[]{2, 1, 3};

//        bubbleSort(array, 3);
//        System.out.println(array[0]);
//        System.out.println(array[1]);
//        System.out.println(array[2]);

        swapArray(array, 3);
        System.out.println(array[0]);
        System.out.println(array[1]);
        System.out.println(array[2]);
    }

    private static void bubbleSort(int[] a, int count) {
        int t, i, j;

        for (i = 0; i < count - 1; i++) {
            for (j = 0; j < count - 1 - i; j++) {
                if (a[j] > a[j + 1]) {
                    t = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = t;
                }
            }
        }
    }

    private static void swapArray(int[] a, int count) {
        int t;
        for (int i = 0; i < count / 2; i++) {
            t = a[i];
            a[i] = a[count - 1 - i];
            a[count - 1 - i] = t;
        }
    }
}
